package com.plm.maque.controller;

import com.alipay.api.AlipayApiException;
import com.plm.maque.domain.bo.BizContent;
import com.plm.maque.domain.vo.ResultBody;
import com.plm.maque.service.PayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Limi
 * @create 2020-06-28 21:09
 */
@Api(tags = "支付相关业务")
@RestController
@RequestMapping("/pay")
public class PayController {

    private final PayService payService;

    public PayController(PayService payService){
        this.payService = payService;
    }

    @ApiOperation(value = "获取订单签名信息")
    @GetMapping("/alipayOrder")
    public ResultBody getOrder() throws AlipayApiException {
        return ResultBody.success(payService.createOrder());
    }

    @ApiOperation(value = "支付宝支付成功后的回调接口")
    @PostMapping("/alipayNotify")
    public String callback(HttpServletRequest request) throws AlipayApiException {
        return payService.handleCallback(request);
    }

    @ApiOperation(value = "查询交易信息")
    @PostMapping("/queryTrade")
    public ResultBody queryTrade(@RequestBody BizContent bizContent) throws AlipayApiException {
        return ResultBody.success(payService.queryTrade(bizContent));
    }

    @ApiOperation(value = "获取麻雀商城订单签名信息")
    @GetMapping("/order")
    public ResultBody order(@RequestParam double allPrice) throws AlipayApiException {
        return ResultBody.success(payService.createMqOrder(allPrice));
    }

}
